#include <iostream>
#include <cstdio>
#include <algorithm>
#include <map>
#include <cstring>
#include <vector>
#include<queue>
using namespace std;
#define MAXL 4000005
#define mod 998244353
int n, m,mun=0;
int dis[MAXL];
int find(int x)
{
	if (dis[x] == x)
		return x;
	return dis[x] = find(dis[x]);
}
int main()
{
	//cin >> n >> m;
	scanf("%d %d", &n, &m);
	for (int i = 0; i <= n; i++)
	{
		dis[i] = i;
	}
	int op, x, y;
	while (m--)
	{
		//cin >> op;
		//cin >> x >> y;
		scanf("%d %d %d", &op, &x, &y);
		if (op == 0)
		{
			dis[find(x)] = find(y);
		}
		else
		{
			if (find(x) == find(y))
			{
				mun = (mun * 2) % mod;
				mun += 1;
			}
			else
				mun = (mun * 2) % mod;
		}
	}
	cout << mun << endl;
	return 0;
}